fig, axes = plt.subplots(2, 2, figsize=(11, 3.8)) # 创建适合幻灯片的四子图画布并控制高度
axes[0, 0].plot(df_fixed['Date'], df_fixed['Close'], color='steelblue', linewidth=1.5) # 绘制指数收盘价走势
axes[0, 0].scatter(df_fixed.loc[error_excess_change, 'Date'], df_fixed.loc[error_excess_change, 'Close'], color='red', s=25, label='异常涨跌') # 标注异常涨跌点
axes[0, 0].set_title('收盘价与异常涨跌') # 设置收盘价子图标题
returns = df_fixed['Daily_Change'].dropna() # 取出有效日收益率
axes[0, 1].hist(returns, bins=15, color='steelblue', edgecolor='white') # 绘制日收益率分布
axes[0, 1].axvline(returns.mean(), color='red', linestyle='--', label=f'均值 {returns.mean():.3f}') # 标注日收益率均值
axes[0, 1].set_title('日收益率分布') # 设置收益率子图标题
axes[1, 0].bar(range(len(df_fixed)), df_fixed['Volume'], color='coral') # 绘制成交量序列
axes[1, 0].set_title('成交量') # 设置成交量子图标题
df_fixed['Amplitude'] = (df_fixed['High'] - df_fixed['Low']) / df_fixed['Low'] * 100 # 计算日内振幅
axes[1, 1].plot(df_fixed['Date'], df_fixed['Amplitude'], color='seagreen', linewidth=1.3) # 绘制日内振幅走势
axes[1, 1].axhline(df_fixed['Amplitude'].mean(), color='red', linestyle='--', label='平均振幅') # 标注平均振幅
axes[1, 1].set_title('日内振幅(%)') # 设置振幅子图标题
axes[0, 0].tick_params(axis='x', labelbottom=False) # 上排行情图隐藏重复日期刻度以避免拥挤
axes[1, 1].xaxis.set_major_locator(plt.matplotlib.dates.AutoDateLocator(minticks=3, maxticks=5)) # 稀疏显示日期刻度
axes[1, 1].xaxis.set_major_formatter(plt.matplotlib.dates.DateFormatter('%m-%d')) # 缩短日期标签
axes[1, 1].tick_params(axis='x', rotation=30) # 旋转底部日期刻度以保持分隔
for ax in axes.flat: ax.grid(True, alpha=0.25) # 统一添加浅色网格
for ax in (axes[0, 0], axes[0, 1], axes[1, 1]): ax.legend(fontsize=16) # 为关键子图添加图例
plt.tight_layout() # 紧凑排列四个子图
plt.show() # 显示数据质量图形
missing_rate = df_fixed.isnull().sum().sum() / df_fixed.size # 计算修复后缺失率
print(f'质量摘要: 缺失率 {missing_rate:.2%};处理 {len(errors)} 类错误;有效记录 {len(df_fixed)}/{len(df_index)}') # 输出数据质量摘要